package cn.yunyichina.provider.base.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by JoeZ on 2016/12/16.
 */
public class ListUtils {
    /**
     * @param args
     */
    public static void main(String[] args) {

        List<Object> list=new ArrayList<Object>();
        for(int i=1;i<101;i++)
        {
            list.add(i);
        }

        List<Object> integers = subLists(list, 30, 2);
        System.out.println(integers);

    }


    /**
     *
     * @param list
     * @param pageSize
     * @param pageNum
     * @return
     */
    public static List subLists(List list , int pageSize , int pageNum){
        int pagesize=pageSize;
        int totalcount=list.size();

        int pagecount=0;

        int m=totalcount%pagesize;

        if  (m>0)
        {
            pagecount=totalcount/pagesize+1;
        }
        else
        {
            pagecount=totalcount/pagesize;
        }

        List<List<Object>> arList = new ArrayList<List<Object>>();

        for(int i=1;i<=pagecount;i++){

            if (m==0)
            {
                List<Object> subList= list.subList((i-1)*pagesize,pagesize*(i));
                arList.add(subList);
            }
            else
            {
                if (i==pagecount)
                {
                    List<Object> subList= list.subList((i-1)*pagesize,totalcount);
                    arList.add(subList);
                }
                else
                {
                    List<Object> subList= list.subList((i-1)*pagesize,pagesize*(i));
                    arList.add(subList);
                }
            }
        }

        List<Object> integers = arList.get(pageNum - 1);
        return integers;
    }
}
